![]() |
PATH![]() |
![]() ![]() |
When AppleScript encounters a variable in a script, it evaluates the variable by getting its value. To create a variable, simply assign it a value:
copy "Mark" to myName
The Copy command takes the data--the string "Mark" --and puts it in the variable myName . You can accomplish the same thing with the Set command:
set myName to "Mark"
Statements that assign values to variables are known as assignment statements.
You can retrieve the value in a variable with a Get command. Run the following script and then display the result in the Script Editor's result window. (You can use the Show Result command to open the result window.)
set myName to "Mark"
get myName
The result window shows that the value in myName is "Mark", the value you stored with the Set command.
You can change the value of a variable by assigning it a new value. A variable can hold only one value at a time. When you assign a new value to an existing variable, you lose the old value. For example, the result of the Get command in the following script is "Robin" .
set myName to "Mark"
set myName to "Robin"
get myName
AppleScript does not distinguish uppercase letters from lowercase variables in variable names; the variables myName , myname , and MYNAME all represent the same value. For related information, see Case Sensitivity.